function [v,R] = bivariate_svmhT(vlag,W,yt,vlast);

% [v,R] = bivariate_svmhT(vlag,W,yt,vlast);

% This file returns a draw from the posterior conditional density
% for the stochastic volatility parameter at time t.  This is conditional
% on the adjacent realization, vlag, as well as the data and parameters 
% of the svol process.  

% v_{t} = (r_{t},s{t})' is a geometric random walk with innovations
% variance W
% vlast is the previous draw in the chain, and is used in the acceptance step. 
% R is a dummy variable that takes a value of 1 if the trial is rejected, 0 if accepted.

% Following JPR (1994), we use a MH step, but with a simpler log-normal proposal density. 

% mean and variance for log(v) (proposal density)
mu = log(vlag);
%Omega_sqrt = sqrtm(W);
[V,D] = eig(W);
Omega_sqrt = real(V*(D.^.5)*V');

% candidate draw from lognormal
vtrial = exp(mu + Omega_sqrt*randn(2,1));

% acceptance probability
Htrial = [vtrial(1) 0; 0 vtrial(2)];
Hlast = [vlast(1) 0; 0 vlast(2)];
lp_trial = -0.5*log(det(Htrial)) - 0.5*yt'*(Htrial\yt);
lp_last = -0.5*log(det(Hlast)) - 0.5*yt'*(Hlast\yt);
accept = min(1,exp(lp_trial - lp_last));

u = rand(1);
if u <= accept,
   v = vtrial;
   R = 0;
else
   v = vlast;
   R = 1;
end
end

